package com.zifeng.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 启动类：
 *   在程序启动时监听其他区块链节点的连接，并连接其他节点，形成区块链网络
 */
@Component
public class P2PRuner implements ApplicationRunner {

    @Autowired
    P2PServer p2PServer;

    @Autowired
    P2PClient p2PClient;

    @Autowired
    BlockCache blockCache;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        p2PServer.initP2PServer(blockCache.getP2pPort());
        p2PClient.connectToPeer(blockCache.getAddress());
        System.out.println("*****难度系数******"+blockCache.getDifficulty());
        System.out.println("*****端口号******"+blockCache.getP2pPort());
        System.out.println("*****节点地址******"+blockCache.getAddress());

    }
}
